//
//  MCMainNavigationController.m
//  TLYL
//
//  Created by miaocai on 2017/6/1.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMainNavigationController.h"
#import "MCPaySelectedLotteryTableViewController.h"
#import "MCMSPopView.h"
#import "MCMoneyPopView.h"
#import "MCPickNumberViewController.h"
#import "MCPaySelectedLotteryModel.h"
@interface MCMainNavigationController ()


@end

@implementation MCMainNavigationController

+(void)load{

  UINavigationBar *bar =[UINavigationBar appearance];
    bar.barTintColor = MC_ColorWithAlpha(54, 128, 211, 1);
    bar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:MC_REALVALUE(14)]};
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    MCMoneyPopView *popView = [MCMoneyPopView alertInstance];
    [popView hideModelWindow];
    MCMSPopView *popView1 = [MCMSPopView alertInstance];
    [popView1 hideModelWindow];
    if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateHighlighted];
        button.size = CGSizeMake(70, 30);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        if ([viewController isKindOfClass:[MCPickNumberViewController class]]) {
            [button addTarget:self action:@selector(popBackToViewController) forControlEvents:UIControlEventTouchUpInside];
        } else {
            [button addTarget:self action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
        }
        
      
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        viewController.hidesBottomBarWhenPushed = YES;
    }

    [super pushViewController:viewController animated:animated];
}

- (void)popBackToViewController{

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认退出" message:@"您退出后号码将被清空" preferredStyle:UIAlertControllerStyleAlert];
        // 添加按钮
        __weak typeof(alert) weakAlert = alert;
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            /*
             * 清空购彩蓝
             */
            MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
            [model removeDataSource];
            
            [self popViewControllerAnimated:YES];
            NSLog(@"点击了确定按钮--%@-%@", [weakAlert.textFields.firstObject text], [weakAlert.textFields.lastObject text]);
            
        }]];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            NSLog(@"点击了取消按钮");
        }]];
        [self presentViewController:alert animated:YES completion:nil];
    
}
@end
